package com.hkts.naturalgas.alarminformation.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.alarminformation.entity.NaturalgasEquipment;
import com.hkts.naturalgas.alarminformation.mapper.NaturalgasEquipmentMapper;
import com.hkts.naturalgas.alarminformation.service.INaturalgasEquipmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2020-09-11
 */
@Service
@Transactional
public class NaturalgasEquipmentServiceImpl extends ServiceImpl<NaturalgasEquipmentMapper, NaturalgasEquipment> implements INaturalgasEquipmentService {


@Autowired
private NaturalgasEquipmentMapper naturalgasEquipmentMapper;

@Override
public IPage<NaturalgasEquipment> selectPage(Page<NaturalgasEquipment> page, NaturalgasEquipment naturalgasEquipment){
        QueryWrapper<NaturalgasEquipment> query = Wrappers.query();
        QueryWrapper<NaturalgasEquipment> entityWrapper = getEntityWrapper(query, naturalgasEquipment);
        return naturalgasEquipmentMapper.selectPage(page, entityWrapper);
        }




@Override
public List<NaturalgasEquipment> selectList(NaturalgasEquipment naturalgasEquipment){
        QueryWrapper<NaturalgasEquipment> query = Wrappers.query();
        QueryWrapper<NaturalgasEquipment> entityWrapper = getEntityWrapper(query, naturalgasEquipment);
        return naturalgasEquipmentMapper.selectList(entityWrapper);
        }

/**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<NaturalgasEquipment> getEntityWrapper(QueryWrapper<NaturalgasEquipment> entityWrapper,NaturalgasEquipment naturalgasEquipment){
        //条件拼接
                if(StringUtils.isNotBlank(naturalgasEquipment.getCreateBy())){
                entityWrapper.like(NaturalgasEquipment.CREATE_BY,naturalgasEquipment.getCreateBy());
                }

                if(StringUtils.isNotBlank(naturalgasEquipment.getUpdateBy())){
                entityWrapper.like(NaturalgasEquipment.UPDATE_BY,naturalgasEquipment.getUpdateBy());
                }

                if(StringUtils.isNotBlank(naturalgasEquipment.getEquipmentName())){
                entityWrapper.like(NaturalgasEquipment.EQUIPMENT_NAME,naturalgasEquipment.getEquipmentName());
                }

                if(StringUtils.isNotBlank(naturalgasEquipment.getEquipmentState())){
                entityWrapper.like(NaturalgasEquipment.EQUIPMENT_STATE,naturalgasEquipment.getEquipmentState());
                }
                if(StringUtils.isNotBlank(naturalgasEquipment.getGateStationId())){
                entityWrapper.like(NaturalgasEquipment.GATE_STATION_ID,naturalgasEquipment.getGateStationId());
                }
                if(StringUtils.isNotBlank(naturalgasEquipment.getEquipmentId())){
                entityWrapper.like(NaturalgasEquipment.EQUIPMENT_ID,naturalgasEquipment.getEquipmentId());
                }
                if(StringUtils.isNotBlank(naturalgasEquipment.getSiteArea())){
                entityWrapper.like(NaturalgasEquipment.SITE_AREA,naturalgasEquipment.getSiteArea());
                }
        return entityWrapper;
        }
        }
